package com.qf.common.sms.config;

import com.aliyun.auth.credentials.Credential;
import com.aliyun.auth.credentials.provider.StaticCredentialProvider;
import com.aliyun.sdk.service.dysmsapi20170525.AsyncClient;
import com.qf.common.sms.AliYunSmsConfigProperties;
import darabonba.core.client.ClientOverrideConfiguration;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import javax.annotation.Resource;

/**
 * @author chengqiang
 * @Create 2024-01-23-13:59
 * @Description:
 */
@Configuration
@EnableConfigurationProperties(AliYunSmsConfigProperties.class)
public class AliYunSmsConfig {

    @Resource
    private AliYunSmsConfigProperties properties;
    // 凭证
    @Bean
    public AsyncClient asyncClient() {
        // 提供静态凭证
        StaticCredentialProvider provider = StaticCredentialProvider.create(Credential.builder().
                accessKeyId(properties.getAccessKeyId()).accessKeySecret(properties.getAccessKeySecret()).build());
        return  AsyncClient.builder().credentialsProvider(provider)
                .overrideConfiguration(ClientOverrideConfiguration.create().setEndpointOverride(properties.getEndpoint()))
                .build();
    }
}
















